package com.branch.dellog

import org.gradle.api.Plugin
import org.gradle.api.Project

/**
 * Created by Ryze on 2017-2-5.
 */
class DelLogPlugin implements Plugin<Project> {

    @Override
    void apply(Project project) {

        LogUtil.project = project

        project.extensions.create('dellogExtension', DelLogExtension);

        project.afterEvaluate {
            //在gradle 构建完之后执行
            LogUtil.error("---dellog afterEvaluate---: ");
            test(project)
        }

        project.task('dellog', {

            LogUtil.error("---dellog task---: ");

            LogUtil.error("dellogExtension: " + project.dellogExtension);

        })

    }

    private static void test(Project project) {
        //在gradle 构建完之后执行
        def projectDir = project.projectDir.toString();
        DelLogExtension extension = project.dellogExtension
        LogUtil.error("projectDir: " + projectDir);
        LogUtil.error("dellogExtension: " + extension);

        DelLogUtil.delLog(new File(projectDir + extension.sourceDir));
        AddCodeUtil.addCode(projectDir, extension)
    }
}
